import React, {Suspense,useEffect } from 'react'
import {useRoutes,useLocation} from "react-router-dom";
import routes from './router/index'
import { useNavigate } from 'react-router'


function App(): JSX.Element {
  let location = useLocation();
  const navigate = useNavigate();
  const routesArr = ['/login','/shezhi']
  useEffect(() => {
    // 这里可以执行你的路由拦截逻辑
    // 比如检查用户是否登录，或者是否有权限访问当前路由
    console.log('Route changed to',routesArr.indexOf(location.pathname) );
    console.log("路由地址",window.location.href)
    if(routesArr.indexOf(location.pathname) == -1){
      let token = localStorage.getItem("token");
      if(!token){
        navigate("/login");
      }

    }
  }, [location]);
  return (
    <>
      <div className="App">
        <Suspense fallback=''>
          {useRoutes(routes)}
        </Suspense>
      </div>
    </>
  )
}

export default App
